package org.finesys.common.redisson.factory;

import cn.hutool.extra.spring.SpringUtil;
import org.finesys.common.redisson.constants.RedissonLockType;
import org.finesys.common.redisson.service.RedissonService;

import java.util.Map;

/**
 * redisson 锁工厂
 */
public class RedissonLockServiceFactory {
    /**
     * 根据类型获取不同的锁实现
     *
     * @param redissonLockType 锁类型
     */
    public static RedissonService getLock(RedissonLockType redissonLockType) {
        Map<String, RedissonService> serviceMap = SpringUtil.getBeansOfType(RedissonService.class);
        return serviceMap.values().stream().filter(s -> redissonLockType.equals(s.lockType())).findFirst().orElse(null);
    }

}
